//
//  UINavigationControllerExtension.swift
//  YYProject
//
//  Created by 陆文宇 on 2017/9/4.
//  Copyright © 2017年 陆文宇. All rights reserved.
//

import UIKit

extension UINavigationController: UINavigationBarDelegate {
    
    public func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
        if viewControllers.count < navigationBar.items?.count ?? 0 {
            return true
        }
        
        let controller = topViewController as? YYController
        let shouldPop = controller?.yy_shouldPop() ?? true
        if shouldPop {
            popViewController(animated: true)
        } else {
            navigationBar.subviews.forEach({ (subview) in
                if subview.alpha > 0 && subview.alpha < 1 {
                    UIView.animate(withDuration: 0.25, animations: { 
                        subview.alpha = 1
                    })
                }
            })
        }
        return false
    }
    
}
